export const useStickyChange = (
  el: string,
  onChange?: (fixed: boolean) => void
) => {
  const isStickyed = ref(false)
  const observer = new IntersectionObserver(
    entries => {
      entries.forEach(entry => {
        isStickyed.value = entry.intersectionRatio === 0
      })
    },
    { threshold: [0, 1], rootMargin: '-113px 0px 0px 0px' }
  )
  watch(isStickyed, v => onChange?.(v), { deep: true, immediate: true })
  onMounted(async () => {
    await nextTick()
    const target = document.querySelector(el)
    if (el && target) {
      observer.observe(target)
    }
  })
  return { isStickyed }
}
